Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Windows.Forms

Public Class FrmCrNXTTongHop
    Private arg As Integer
    Private data As DataTable
    Private thang, nam, kho, makho As String
    Private tiendauky As Double
    Private customerReport As ReportDocument

    Public Sub setArg(ByVal i As Integer)
        arg = i
    End Sub

    Delegate Sub WaitDelegate()

    Private Sub FrmCrNXTTongHop_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        globalVariale.runWaitting = True
        Dim wd As New WaitDelegate(AddressOf moduleWaitting.runningWait)
        wd.BeginInvoke(Nothing, Nothing)
        Dim sqlQuery As String = ""

        If arg = 1 Then
            'sqlQuery = "SELECT * FROM tbl_dot_NhapXuatTongHop where  recycleID='" & nam & thang & "' AND (soluong_dauky<>0 OR soluongnhap_trongky<>0 OR soluongxuat_trongky<>0 OR soluongcuoiky<>0)ORDER BY ten_bietduoc"
            sqlQuery = "select ma_hanghoa,ten_bietduoc,donvi_banchan,sum(soluong_dauky) as soluong_dauky,sum(thanhtien_dauky) as thanhtien_dauky ,sum(soluongnhap_trongky) as soluongnhap_trongky,sum(thanhtiennhap_trongky) as thanhtiennhap_trongky ,sum(soluongxuat_trongky) as soluongxuat_trongky,sum(thanhtienxuat_trongky) as thanhtienxuat_trongky,sum(soluongcuoiky) as soluongcuoiky,sum(thanhtiencuoiky) as thanhtiencuoiky "
            sqlQuery += " from tbl_dot_nhapxuattonghop_lo where recycleid = '" & nam & thang & "'  group by ma_hanghoa  ORDER BY ten_bietduoc ;"
        Else
            sqlQuery = "SELECT * FROM tbl_dot_NhapXuatTongHop_ketoan where  recycleID='" & nam & thang & "' AND (soluong_dauky<>0 OR soluongnhap_trongky<>0 OR soluongxuat_trongky<>0 OR soluongcuoiky<>0)ORDER BY ten_bietduoc"
        End If

        Dim reportPath = Application.StartupPath & "\" & "crNhapXuatTonTongHop.rpt"
        customerReport = New ReportDocument()
        customerReport.Load(reportPath)
        customerReport.SetDataSource(moduleReportConfig.GetDataTable(sqlQuery))
        customerReport.SetParameterValue("month", thang)
        customerReport.SetParameterValue("year", nam)
        customerReport.SetParameterValue("TKho", kho)
        customerReport.SetParameterValue("company", globalVariale.COMPANY)
        customerReport.SetParameterValue("address", globalVariale.ADDRESS)
        Me.CrNXTTongHopview.ReportSource = customerReport

        globalVariale.runWaitting = False
    End Sub

    Private Sub BtnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Close()
    End Sub
    Public Sub setThang(ByVal s As String)
        thang = s
    End Sub

    Public Sub setNam(ByVal s As String)
        nam = s
    End Sub
    Public Sub setKho(ByVal s As String)
        kho = s
    End Sub
    Public Sub setMakho(ByVal s As String)
        makho = s
    End Sub

    Public Sub setData(ByVal d As DataTable)
        data = d
    End Sub


End Class
